/**
 * @author wangC
 * @create 2020-06-18 下午11:45
 * @Description  synchronized 可重入
 **/
public class Synchronized_2 {

     //一个同步方法调另一个同步方法，一个线程已经拥有某个对象的锁，再次申请的时候仍然会得到该对象的锁.

    synchronized void m1() {
        System.out.println("m1 start");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        m2();
        System.out.println("m1 end");
    }


    synchronized void m2() {
        System.out.println("m2 start");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("m2 end");
    }

    public static void main(String[] args) {
        Synchronized_2 sync_1 = new Synchronized_2();
        new Thread(sync_1::m1, "m1").start();
    }
}
